function getXmlHttpRequest(){
    if (window.XMLHttpRequest) {
        return new window.XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
            return new ActiveXObject("Msxml2.XMLHTTP.6.0");
        } catch (e) {}
        try {
            return new ActiveXObject("Msxml2.XMLHTTP.3.0");
        } catch (e) {}
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {}
        return null;
    }
    return null;
}

// synchronous request
function call(page, params) {
    var xhr=getXmlHttpRequest();
    if(xhr) {
        xhr.open("POST", page, false);    //+ "?" + params
        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        xhr.setRequestHeader('Content-length', params.length);
        xhr.setRequestHeader('Connection', 'close');
        xhr.send(params);
        return xhr.responseText;
    } else {
        alert("Questo browser non supporta l'oggetto XmlHttpRequest!");
        return false;
    }
}

// asynchronous request
var xhr;
function makeRequest(page, params) {
    xhr=getXmlHttpRequest();
    if(xhr) {
        xhr.onreadystatechange = getResponseValue;
        xhr.open("POST", page, false);    //+ "?" + params
        xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
        xhr.setRequestHeader('Content-length', params.length);
        xhr.setRequestHeader('Connection', 'close');
        xhr.send(params);
    } else {
        alert("Questo browser non supporta l'oggetto XmlHttpRequest!");
        return false;
    }
}

function getResponseValue() {
    if (xhr.readyState === 4) { // richiesta completata
        if (xhr.status === 200) {   // richiesta corretta (https://developer.mozilla.org/en/HTTP/HTTP_response_codes#200)
            return xhr.responseText;
        }
    }
    return false;
}
